import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import path from "path";
import ChildrenView from '@/components/ChildrenView.vue'
/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  //登录路由

  {
    path: '/sys',
    name:'sys',
    component: Layout,
    meta: { title: '系统管理', icon: 'dashboard' },
    redirect: '/sys/user',
    children: [
      {
        path: 'user',
        name: 'dashboard',
        component: () => import('@/views/sys/user.vue'),
        meta: { title: '用户管理', icon: 'dashboard' }
      },
      {
        path: 'role',
        name: 'dashboard',
        component: () => import('@/views/sys/role.vue'),
        meta: { title: '角色管理', icon: 'dashboard' }
      },
      {
        path: 'menu',
        name: 'dashboard',
        component: () => import('@/views/sys/menu.vue'),
        meta: { title: '菜单管理', icon: 'dashboard' }
      }]
  },
  {
    path: '/',
    name:'home',
    component: Layout,
    meta: { title: '采购系统', icon: 'dashboard' },
    redirect: '/dashboard',
    children: [
      {
        path: '/dashboard',
        name: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        meta: { title: 'Dashboard', icon: 'dashboard' }
      },
      {
        path: '/supplier',
        name:'provider',
        component: ChildrenView,
        meta: { title: '供应商平台', icon: 'dashboard' },
        redirect: '/supplier/supplier',
        children: [
          {
            path: 'supplier',
            name: 'Supplier',
            component: () => import('@/views/supplier/index'),
            meta: { title: '供应商基本信息查看', icon: 'dashboard' }
          },
          // {
          //   path: 'changePassword',
          //   name: 'changePassword',
          //   component: () => import('@/views/changePassword/index'),
          //   meta: { title: '修改登录密码', icon: 'dashboard' }
          // },
          {
            path: 'material',
            name: 'material',
            component: () => import('@/views/material/index'),
            meta: { title: '供应商产品的维护', icon: 'dashboard' }
          },
          {
            path: 'product-category',
            name: 'product-category',
            component: () => import('@/views/productCategory/index'),
            meta: { title: '产品类别的维护', icon: 'dashboard' }
          },
          {
            path: 'quote',
            name: 'Quote',
            component: () => import('@/views/quote/index'),
            meta: { title: '报价维护', icon: 'dashboard' }
          },
          //报价维护详情子路由
          {
            path: 'details',
            name: 'details',
            component: () => import('@/views/quote/details.vue'),
            show:false
          },
          {
            path: 'quoteadd',
            name: 'QuoteAdd',
            component: () => import('@/views/quotedetail/index.vue'),
            meta: { title: '询价书报价', icon: 'dashboard' }
          },
          //询价书报价子路由详情子路由
          {
            path: 'viewDetails',
            name: 'viewDetails',
            component: () => import('@/views/quotedetail/viewDetails.vue'),
            show:false
          },
          {
            path: 'contract',
            name: 'provider-contract',
            component: () => import('@/views/contract/index'),
            meta: { title: '合同查询', icon: 'dashboard' }
          }]
      },
//计划员路由
      {
        path: "/plan",
        name: "plan",
        meta: {
          title: "计划员",icon: "dashboard"
        },
        component: ChildrenView,
        // redirect: "/plan/plan2/supplier"

        children: [

          {
            path: 'requirement',
            name: 'requirement',
            component: ChildrenView,
            meta: { title: '需求计划处理', icon: 'dashboard' }
            ,
            children: [

              {
                path: 'type-in',
                component: () => import('@/views/orders/type-in.vue'),
                name: 'type-in',
                meta: {title: '需求计划录入'},

              },

              {
                path: 'orders',
                component: () => import('@/views/orders'),
                name: 'orders',
                meta: {title: '需求计划查询'},

              },
            ],
          },
          //采购计划路由
          {
            path: "stock",
            name: "stock",
            component:()=>import('@/components/ChildrenView.vue'),
            meta: {
              title: "采购计划管理",
              icon: "dashboard"
            },
            children:[
              {
                path: "compile",
                name: "stock-compile",
                component: () => import('@/views/stock/indexOrders.vue'),
                meta: {
                  title: "编制采购计划",
                  icon: "dashboard"
                },
              },
              {
                path: "select",
                name: "select",
                component: () => import('@/views/stock'),
                meta: {
                  title: "查询采购计划",
                  icon: "dashboard"
                },
              },
              {
                path: "lssue",
                name: "lssue",
                component: () => import('@/views/stock/index-lssue.vue'),
                meta: {
                  title: "采购计划下达",
                  icon: "dashboard"
                },
              },
              {
                path: "noapproval",
                name: "noapproval",
                component: () => import('@/views/stock/index-noapproval.vue'),
                meta: {
                  title: "未通过审批采购计划",
                  icon: "dashboard"
                },
              },
              {
                path: "stock-lssue",
                name: "stock-lssue",
                component: () => import('@/views/stock/index-noapproval.vue'),
                show: false
              },
              {
                path: "editStock",
                name: "editStock",
                component: () => import('@/views/stock/stock-edit.vue'),
                show: false
              },
              {
                path: "stockDetails",
                name: "stockDetails",
                component: () => import('@/views/stock/stock-details.vue'),
                show: false
              },
            ]
          },
          // 供应商管理模块
          {
            path: "planMaterial",
            name: "planMaterial",
            component: ChildrenView,
            meta: {
              title: "供应商管理",
              icon: "dashboard"
            },
            children: [
              {
                path: "supplierInfo",
                name: "supplierInfo",
                component: () => import('@/views/supplierInfo/index.vue'),
                meta: {
                  title: "供应商基本信息查询",
                  icon: "dashboard"
                }
              },
              {
                path: "supplierProductCategory",
                name: "supplierProductCategory",
                component: () => import('@/views/supplierProductCategory/index.vue'),
                meta: {
                  title: "供应商产品类别管理",
                  icon: "dashboard"
                },
              },

              {
                path: "supplierAdd",
                name: "supplierAdd",
                component: () => import('@/views/supplierAdd/index.vue'),
                meta: {
                  title: "添加供应商",
                  icon: "dashboard"
                }
              },
            ]
          }
        ]
      },
      //合同管理
      {
        path: "/contract",
        name: "contract",
        component: ChildrenView,
        // component:()=>import('@/components/ChildrenView.vue'),
        meta: {
          title: "合同管理",
          icon: "dashboard",
        },
        children: [
          {
            path: "apply",
            name: "apply",
            component: ChildrenView,
            meta: {
              title: "编制合同申请",
              icon: "dashboard"
            },
            children:[
              {
                path: "apply",
                name: "apply-apply",
                component: () => import('@/views/contractapply/enquire.vue'),
                meta: {
                  title: "编制合同申请",
                  icon: "dashboard"
                }
              },
              {
                path: "make-contract-apply",
                name: "make-contract-apply",
                component: () => import('@/views/contractapply/make-contract-apply.vue'),
                // meta: {
                //   title: "编制合同申请",
                //   icon: "dashboard"
                // },
                show:false
              },
              {
                path: "contract-apply-detail",
                name: "contract-apply-detail",
                component: () => import('@/views/contractapply/detail.vue'),

                show:false
              },
              {
                path: "confirmation",
                name: "confirmation",
                component: () => import('@/views/contractapply/confirm.vue'),
                meta: {
                  title: "确认合同申请",
                  icon: "dashboard"
                }
              },
              {
                path: "contract-apply",
                name: "contract-apply",
                component: () => import('@/views/contractapply/index.vue'),
                meta: {
                  title: "查询合同申请及报批",
                  icon: "dashboard"
                }
              },
              {
                path: "not-passed",
                name: "not-passed",
                component: () => import('@/views/contractapply/not-pass.vue'),
                meta: {
                  title: "未通过合同申请",
                  icon: "dashboard"
                }
              }
            ]

          },
          {
            path: "contract",
            name: "contract-safeguard",
            component: ChildrenView,
            meta: {
              title: "合同申请维护",
              icon: "dashboard"
            },
            children:[
              {
                path: "compile",
                name: "contract-compile",
                component: () => import('@/views/contract/compile-contract.vue'),
                meta: {
                  title: "编制合同",
                  icon: "dashboard"
                }
              },
              {
                path: "make-contract",
                name: "make-contract",
                component: () => import('@/views/contract/make-contract.vue'),
                show:false
              },
              {
                path: "confirm",
                name: "confirm",
                component: () => import('@/views/contract/confirm-contract.vue'),
                meta: {
                  title: "确认合同",
                  icon: "dashboard"
                }
              },
              {
                path: "maintenance",
                name: "maintenance",
                component: () => import('@/views/contract/maintenance-contract.vue'),
                meta: {
                  title: "维护合同",
                  icon: "dashboard"
                }
              },
              {
                path: "archive",
                name: "archive",
                component: () => import('@/views/contract/contract-archive.vue'),
                meta: {
                  title: "合同归档",
                  icon: "dashboard"
                }
              }
            ]
          },
          {
            path: "make-contract",
            name: "makeContract",
            component: () => import('@/views/contract/make-contract.vue'),
            show:false
          },
        ]
      },
      //采购员的询价与报价路由
      {
        path: "/purchasing",
        name: "purchasing",
        component: ChildrenView,
        // component:()=>import('@/components/ChildrenView.vue'),
        meta: {
          title: "采购员的询价与报价",
          icon: "dashboard",
        },
        children: [
          {
            path: "purchaser",
            name: "purchaser",
            component: ChildrenView,
            meta: {
              title: "询价书业务处理",
              icon: "dashboard"
            },
            children:[
              {
                path: "work-out",
                name: "work-out",
                component: ChildrenView,
                meta: {
                  title: "编制询价书",
                  icon: "dashboard"
                },
                children:[
                  {
                    path: "work-out1",
                    name: "work-out1",
                    component: () => import('@/views/enquire/index.vue'),
                    meta: {
                      title: "编制询价书",
                      icon: "dashboard"
                    }
                  },
                  {
                    path: "make-enquire-apply",
                    name: "make-enquire-apply",
                    component: () => import('@/views/enquire/MakeEnquireApply.vue'),
                    // meta: {
                    //   title: "编制询价书",
                    //   icon: "dashboard"
                    // },
                    show:false
                  },
                  {
                    path: "list",
                    name: "list",
                    component: () => import('@/views/enquire/enquire-update-or-delete.vue'),
                    meta: {
                      title: "询价书列表",
                      icon: "dashboard"
                    }
                  },
                  {
                    path: "update-enquire-apply",
                    name: "update-enquire-apply",
                    component: () => import('@/views/enquire/UpdateEnquireApply.vue'),
                    show:false
                  }
                ]
              }
            ]
          }
        ]
      },
      //财务部长业务处理路由
      {
        path: '/finance',
        name:'finance',
        component: ChildrenView,
        meta: { title: '财务部长业务处理', icon: 'dashboard' },
        redirect: '/dashboard',
        children: [{
          path: 'quoteadd',
          name: 'finance-quoteAdd',
          component: () => import('@/views/stock/index'),
          meta: { title: '待审批采购计划', icon: 'dashboard' }
        },
          {
            path: 'details',
            name: 'finance-contract-apply-deatil',
            component: () => import('@/views/contractapply/finance/detail.vue'),
          },
          {
            path: 'contract',
            name: 'finance-contract-apply',
            component: () => import('@/views/contractapply/finance/index.vue'),
            meta: { title: '待审批合同申请', icon: 'dashboard' }

          }]
      },
      //计划部长业务处理路由
      {
        path: '/planning',
        name:'planning',
        component: ChildrenView,
        meta: { title: '计划部长业务处理', icon: 'dashboard' },
        redirect: '/dashboard',
        children: [{
          path: 'quoteadd',
          name: 'planning-quoteadd',
          component: () => import('@/views/stock/index'),
          meta: { title: '待审批采购计划', icon: 'dashboard' }
        },
          {
            path: 'detail',
            name: 'planning-contract-apply-detail',
            component: () => import('@/views/contractapply/planer/detail.vue'),
          },
          {
            path: 'contract-apply',
            name: 'planning-contract-apply',
            component: () => import('@/views/contractapply/planer/index.vue'),
            meta: { title: '待审批合同申请', icon: 'dashboard' }

          },
          {
            path: 'employee',
            name: 'employee',
            component: () => import('@/views/employee/index.vue'),
            meta: { title: '员工管理', icon: 'dashboard' }

          }]
      },
      //厂长业务处理路由
      {
        path: '/factory',
        name:'factory',
        component: ChildrenView,
        meta: { title: '厂长业务处理', icon: 'dashboard' },
        redirect: '/factory/contract-apply',
        children: [{
          path: 'contract-apply',
          name: 'factory-contract-apply',
          component: () => import('@/views/contractapply/leader/index.vue'),
          meta: { title: '待审批合同申请', icon: 'dashboard' }
        },
          {
            path: 'detail',
            name: 'factory-contract-apply-detail',
            component: () => import('@/views/contractapply/leader/detail.vue'),
          },
          // {
          //   path: 'contract',
          //   name: 'contract',
          //   component: () => import('@/views/stock/index'),
          //   meta: { title: '待审批采购计划', icon: 'dashboard' }
          // }
        ]
      },

    ]
  },


  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]
let mainRoutes =[
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
//404页面路由
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
]
mainRoutes.push(...constantRoutes)
console.log(mainRoutes)
const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: mainRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
